class Solution {//leetcode43——字符串相乘
public:
    string multiply(string num1, string num2) {
        string ret;
        int n=num1.size(),m=num2.size();
        vector<int> num(n+m-1);
        reverse(num1.begin(),num1.end());
        reverse(num2.begin(),num2.end());
        for(int j=0;j<n;j++){//无进位结果相加
            for(int i=0;i<m;i++){
                int cnt1=0,cnt2=num2[i]-'0';
                cnt1=num1[j]-'0';
                num[i+j]+=(cnt1*cnt2);
            }
        }
        //处理进位
        int carry=0;
        for(int i=0;i<m+n-1;i++){
            carry+=num[i];
            ret.push_back((carry%10)+'0');
            carry/=10;
        }
        while (carry){
            ret.push_back((carry%10)+'0');
            carry/=10;
        }
        
        while(ret.size()>1&&ret.back()=='0') ret.pop_back();
        reverse(ret.begin(),ret.end());
        return ret;
    }
};